# -*- coding:utf-8 -*-
"""
@author: Jioccer
@time: 2023/9/9 13:46 
@file: 屏蔽更新.py
@project: 一键关闭Windows更新
@describe: TODO
"""
import re
import winreg

import winreg

# 定义注册表键路径
key_path = r"SOFTWARE\Microsoft\WindowsUpdate\UX\Settings"

try:
    # 打开注册表键
    with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key_path, 0, winreg.KEY_WRITE) as key:
        # 定义要设置的注册表值
        registry_values = {
            "FlightSettingsMaxPauseDays": 0x1b58,  # DWORD值
            "PauseFeatureUpdatesStartTime": "2023-07-07T10:00:52Z",  # 字符串值
            "PauseFeatureUpdatesEndTime": "2042-09-05T09:59:52Z",  # 字符串值
            "PauseQualityUpdatesStartTime": "2023-07-07T10:00:52Z",  # 字符串值
            "PauseQualityUpdatesEndTime": "2042-09-05T09:59:52Z",  # 字符串值
            "PauseUpdatesStartTime": "2023-07-07T09:59:52Z",  # 字符串值
            "PauseUpdatesExpiryTime": "2042-09-05T09:59:52Z",  # 字符串值
        }

        for value_name, value_data in registry_values.items():
            if isinstance(value_data, int):
                # 设置DWORD值
                winreg.SetValueEx(key, value_name, 0, winreg.REG_DWORD, value_data)
                print(f"已设置DWORD注册表值: {value_name}")
            elif isinstance(value_data, str):
                # 设置字符串值
                winreg.SetValueEx(key, value_name, 0, winreg.REG_SZ, value_data)
                print(f"已设置字符串注册表值: {value_name}")
            else:
                print(f"不支持的注册表值类型: {value_name}")

    print("注册表操作执行完成")

except Exception as e:
    print(f"发生错误: {e}")
